﻿using Microsoft.Practices.Unity;
using RockBus.Initialization.Interfaces;
using RockBus.Routing;
using RockBus.Routing.Interfaces;
using RockBus.Routing.SendPorts;
using RockBus.Transport.Db;

namespace RockBus.Composition
{
    public class DbSubscriptionPersistenceDbMessagePersistenceDependencyManager : DependencyManagerBase
    {
        protected override void FillContainer(IUnityContainer container)
        {
            this.FillContainerWithSqlDbSubscriptionRespository(container);
            this.FillContainerWithSqlDbMessageRepository(container);

            container
            .RegisterType<IMessageRepositoryHelper, MessageRepositoryHelper>(new ContainerControlledLifetimeManager())
            .RegisterType<IMessageProcessor, DbMessageProcessor>(InstanceNames.PersistenceSendPort, new ContainerControlledLifetimeManager())
            .RegisterType<IMessageProcessor, DeliverySendPort>(InstanceNames.DeliverySendPort, new ContainerControlledLifetimeManager())
            .RegisterType<IMessageProcessor, DbErrorProcessor>(InstanceNames.ErrorManager, new ContainerControlledLifetimeManager())

            // PublisherManager dependencies
            .RegisterType<IMessagePublisher, DbMessagePublisher>(InstanceNames.DbMessagePublisher, new ContainerControlledLifetimeManager())
            .RegisterType<IPublisherManager, PublisherManager>(new ContainerControlledLifetimeManager())
            .RegisterType<IInitialization, PublisherManagerInitialization>(InstanceNames.PublisherManagerInitialization, new ContainerControlledLifetimeManager())
            ;
        }
    }
}